package com.hnevc.gui;

import java.awt.GridLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class GridLayoutDemo extends JFrame{

	JPanel p;
	JButton[] btns;
	public GridLayoutDemo(){
		super("网格布局");
		p = new JPanel(new GridLayout(2,3));
		btns = new JButton[6];
		for(int i=0;i<btns.length;i++){
			btns[i] = new JButton("按钮"+(i+1));
		}
		for(int i=0;i<btns.length;i++){
			p.add(btns[i]);
		}
		this.add(p);
		this.setSize(300,200);
		this.setLocation(200,200);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setVisible(true);
	}
	public static void main(String[] args) {
		new GridLayoutDemo();
	}
}
